package cn.wolfcode.luowowo.util;

import cn.wolfcode.luowowo.exception.LogicException;
import com.aliyun.oss.common.utils.StringUtils;


import java.util.regex.Pattern;

//字符串工具类
public class MyUtils {
    //判断一个字符串是否有内容,没有就抛出异常,异常信息调用者指定
    public static void hasLength(String str , String msg) {
        //去除前后空格
        String s = StringUtils.trim(str);
        if (s == null || s.isEmpty()){
            throw new LogicException(msg);

        }
    }
    /**
     * 校验两个字符串内容是否一致,不等就抛出异常,异常信息调用者指定
     */
    public static void isEquals(String s1 , String s2 , String msg) {
        if(s1 == null || s2 == null){
            throw new RuntimeException("比较的两个参数不能为空");
        }else {
            if(!s1.equals(s2)){
                throw new LogicException(msg);
            }
        }

    }

    public static void isPhonePattern(String phone) {
        if(!Pattern.matches("^1\\d{10}$",phone)){
            throw new LogicException("手机号格式错误，请重新输入");
        }
    }

    public static void isSequence(Integer Sequence) {
        if(Sequence == null){
            throw new LogicException("请输入序号");
        }
    }
}
